/*
 * Copyright (C) 2007 Evan Long    longx223 (at) umn (dot) edu
 *
 */

/**
 * @file   cvector.h
 * @author Evan Long
 * 
 * @brief  cvector is a dynamic sizing array. 
 * 
 * 
 */

#ifndef CVECTOR_H
#define CVECTOR_H

/**
 * cvector_t keeps track of information for a specific instance of a cvector
 *
 * @param size Maximum number of elements that can be inserted into the vector
 * before it needs to be resized. 
 * @param end_index Keeps track of the last element in the vector. 
 * @param element_size Amount of memory in bytes needed to store a single 
 * element.
 */
typedef struct cvector
{
  int size;
  int end_index;
  int element_size;
  void* data;
} cvector_t;

/** 
 * Create a new cvector that stores will be used to store elements of a 
 * specific size.
 * 
 * @param element_size Size of the type of elements that will be stored in this
 * instance of cvector.
 * 
 * @return Pointer to a newly allocated cvector.
 */
cvector_t* new_cvector(int element_size);

/** 
 * Insert an element at the end of a specific instance of cvector. The element
 * will be copied into memory already allocated for cvector.
 * 
 * @param vec The instance of cvector to be modified.
 * @param element Pointer to the data that will be added.
 */
void add_element(cvector_t* vec, void* element);

/** 
 * Returns a pointer to the element at a given index.
 * 
 * @param vec The instance of cvector.
 * @param idx Index of the element to have a pointer returned to.
 * 
 * @return Pointer to the element at idx
 */
void* element_at(cvector_t* vec, int idx);

/** 
 * Free all memory associated with a paticular instance of cvector.
 * 
 * @param vec Instance of cvector to be freed
 */
void free_vector(cvector_t* vec);

#endif
